package com.itheima01.day05;

import java.util.Random;
import java.util.Scanner;

/**
 * @author 刘全
 * @date 2021/7/6
 */
/*
需求：设计一个方法用于数组遍历，要求遍历的结果是在一行上的。例如：[11, 22, 33, 44, 55]

 */
public class MethodTest05 {
    public static void main(String[] args) {
        arr();
    }

    public static void arr() {
        Scanner sc = new Scanner(System.in);
        Random r = new Random();
        System.out.println("请输入一个数作为数组的长度:");
        int length = sc.nextInt();
        int[] arr = new int[length];

        for (int i = 0; i < length; i++) {
            int num = r.nextInt(99) + 1;
            arr[i] = num;
        }
        System.out.print("[");
        int i = 0;
        for (; i < length ; i++) {
            if (i != length - 1) {
                System.out.print(arr[i] + ",");
            } else {
                System.out.print(arr[i] + "]");
            }
        }
    }
}
